package com.datatools.ui.frame;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.io.Serializable;

/**
 * 右面板
 */
public class RightPanel extends JTabbedPane implements Serializable {
    private static final long serialVersionUID = 1L;

    public RightPanel() {
        this.setLayout(new BorderLayout());
        //右面板边框
        //Border border = BorderFactory.createLineBorder(Color.green);
        //this.setBorder(border);
        this.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    }

    /**
     * 为新添加的Tab组件的Tab标题添加关闭按钮和事件
     *
     * @param compontPanel 当前页签Panel
     */
    public void addTabCloseTitle(final JPanel compontPanel) {

        JPanel TabTitlePane = new JPanel();
        //透明
        TabTitlePane.setOpaque(false);
        TabTitlePane.setLayout(new BorderLayout());
        JLabel title = new JLabel("新建查询");
        TabTitlePane.add(title, BorderLayout.CENTER);
        JLabel closeBtn = new JLabel("x");
        closeBtn.setForeground(Color.LIGHT_GRAY);
        TabTitlePane.add(closeBtn, BorderLayout.EAST);
        //关闭事件
        JTabMouseAdapter jTabMouseAdapter = new JTabMouseAdapter();
        jTabMouseAdapter.setCloseBtn(closeBtn);
        jTabMouseAdapter.setjTabbedPane(this);
        jTabMouseAdapter.setCompontPanel(compontPanel);
        closeBtn.addMouseListener(jTabMouseAdapter);
        //添加Tab可关闭标题
        this.setTabComponentAt(this.indexOfComponent(compontPanel), TabTitlePane);
    }

}
